﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using DataAccessLayer;

namespace BusinessLayer
{
    public class UpdateEquip
    {
        public string Equip_ID { get; set; }
        public string Name { get; set; }
        public decimal Price { get; set; }
        public string Description { get; set; }
        public string  image { get; set; }
        public string Category { get; set; }

        public UpdateEquip()
        {
            Equip_ID = "";
            Name = "";
            Price = 0;
            Description = "";
            image = "";
            Category = "";
        }
        public UpdateEquip(string id, string na, decimal pr, string de, string im, string ca)
        {
            Equip_ID = id;
            Name = na;
            Price = pr;
            Description = de;
            image = im;
            Category = ca;
        }

        //GET EQUIPMENT BY ID
        public List<UpdateEquip> get_equipment_even_by_id()
        {
            List<csparameterListType> par = new List<csparameterListType>();
            List<UpdateEquip> objlist = new List<UpdateEquip>();
            DataAccessLayer.csDAL objdal = new DataAccessLayer.csDAL();
            IDataReader datareader = null;

            datareader = objdal.executespreturndr("GET_EQUIPMENT");
            while (datareader.Read())
            {
                UpdateEquip objP = new UpdateEquip();
                populate_reader(datareader, objP);
                objlist.Add(objP);
            }
            return objlist;
        }

        private void populate_reader(IDataReader datareader, UpdateEquip objP)
        {
            objP.Equip_ID = datareader.GetString(0);
            objP.Name = datareader.GetString(1);
            objP.Price = datareader.GetDecimal(2);
            objP.Description = datareader.GetString(3);
            objP.image = datareader.GetString(4);
            objP.Category = datareader.GetString(5);
        }

        public void update_equipment()
        {
            DataAccessLayer.csDAL objdal = new DataAccessLayer.csDAL();
            List<csparameterListType> par = new List<csparameterListType>();

            par.Add(new csparameterListType("@EQUIPMENT_NUMBER", SqlDbType.VarChar, Equip_ID));
            par.Add(new csparameterListType("@EQUIPMENT_NAME", SqlDbType.VarChar,Name));
            par.Add(new csparameterListType("@PRICE", SqlDbType.Decimal,Price));
            par.Add(new csparameterListType("@EQUIPMENT_DESCRIPTION", SqlDbType.VarChar,Description));
            par.Add(new csparameterListType("@EQUIPMENT_IMAGE", SqlDbType.VarChar,image));
            par.Add(new csparameterListType("@CATEGORY", SqlDbType.VarChar,Category));

            objdal.executespreturnnd("UPDATE_EQUIPMENT", par);
        }

        public void delete_equipment()
        {
            DataAccessLayer.csDAL objdal = new DataAccessLayer.csDAL();
            List<csparameterListType> par = new List<csparameterListType>();

            par.Add(new csparameterListType("@EQUIPMENT_NUMBER", SqlDbType.VarChar, Equip_ID));

            objdal.executespreturnnd("DELETE_EQUIPMENT", par);  
        }
    }
}